const {
  $util,
} = getApp();
Page({
  data: {
    selectedDate: '',
    imgs: [],
    title: '',
    content: '',
    conLen: 0,
  },
  /**
   * 选择谈话日期
   */
  selectDate(e) {
    this.setData({
      selectedDate: e.detail.value,
    });
    console.log(e.detail.value);
  },
  setRemark(e) {
    this.setData({
      title: e.detail.value,
    });
  },
  setContent(e) {
    this.setData({
      content: e.detail.value,
      conLen: e.detail.value.length,
    });
  },
  /**
   * 获取最新的 待提交的图片列表
   * @param {object} e 来自组件的数据
   * @param {string[]} e.detail
   * @return
   */
  imgsOnChange(e) {
    this.setData({
      imgs: e.detail,
    });
  },
  /**
   * 提交
   */
  submit() {
    const D = this.data;
    const {
      title,
      imgs,
      content,
    } = D;
    if (title.trim() === '') {
      wx.showModal({
        title: '提示',
        content: '请填写标题',
        showCancel: false,
      });
      return;
    }
    if (content.trim() === '') {
      wx.showModal({
        title: '提示',
        content: '请填写事项描述',
        showCancel: false,
      });
      return;
    }
    $util.request({
      url: 'entry/wxapp/partyman.home.setcareerupload',
      data: {
        remark: title,
        comment: content,
        img: imgs.toString(),
      },
      success: (res) => {
        wx.showToast({
          title: '提交成功',
          icon: 'none',
          duration: 1000,
          mask: true,
          success: () => {
            setTimeout(() => {
              wx.navigateBack();
            }, 1000);
          },
        });
      },
    });
  },
});